<%@ page import="ro.gateway.aida.utils.HttpUtils,
ro.gateway.aida.usr.LoginServlet,
ro.gateway.aida.usr.UserConstants,
ro.gateway.aida.usr.User,
ro.gateway.aida.usr.Arbiter,
ro.gateway.aida.usr.Perms,
ro.xblue.translator.LanguageBean,
ro.gateway.aida.db.PersistenceManager,
		ro.gateway.aida.db.PersistenceToken,
ro.xblue.translator.TranslatorUtils"
%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> 

<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>

<%

     String ctx = request.getContextPath();

     String def_referer = ctx + "/index.jsp";

     String referer = HttpUtils.getReferer(

          request, LoginServlet.PNAME_REFERER, def_referer, new String[] {"login"});

     session.setAttribute(LoginServlet.PNAME_REFERER, referer);



     String[] errors = (String[]) request.getAttribute(LoginServlet.PNAME_ERRORS);



     // cookiz

     String last_logged_usr = "";

     long last_login = 0;

     Cookie cukiz[] = request.getCookies();

     if (cukiz == null) cukiz = new Cookie[0];

     for ( int i = 0; i < cukiz.length; i++ ) {

          Cookie cookie = cukiz[ i ];

//          System.out.println( cookie.getName() );

          if (LoginServlet.LAST_LG_USR_COOKIE.equals(cookie.getName())) {

               last_logged_usr = cookie.getValue();

          } else if (LoginServlet.LAST_LG_TIME_COOKIE.equals(cookie.getName())) {

               last_login = HttpUtils.getLong(cookie.getValue(), 0);

          }

     }

     if (System.currentTimeMillis() - last_login > LoginServlet.COOKIE_LIFETIME) {

          last_logged_usr = "";

     }

     // end of cookiz



     User user = ( User ) session.getAttribute( UserConstants.LOGGED_USER );

     

     LanguageBean lang_bean = TranslatorUtils.getCurrentLanguage(request, application);

	String lang=lang_bean.language;
PersistenceToken token = PersistenceManager.
						  tokenLookup(application);
	Arbiter ar=Arbiter.getManager(token);

%>

<trans:initPage module="users" />





<table align="center" width="100%" cellpadding="3" cellspacing="1" class="text">

  <tr bgcolor="#FFFFFF">

    <td width="50%" valign="top">

      <table align="center" width="100%" border="0" cellpadding="5" cellspacing="1" background=images/pixelbgtable.gif>

        <tr>

          <td background=images/pixelbgtable.gif class="textalb"><trans:showPageMessage label="login.view" />

          </td>

        </tr>

        <form name="form1" method="post" action="<%=ctx%>/activity/search?mode=newsearch"><tr>

            <td colspan="2" bgcolor="#FFFFFF" class="text_searchbold" valign="top">

              <p><trans:showPageMessage label="login.chooseprojects" />

              <input type="hidden" name="stype" value="viewall">

                <input type="submit" name="Button" value="Go" class="butonsave">

            



          </td>

        </tr>

</form>

        <form name="form2" method="post" action="<%=ctx%>/activity/search?mode=newsearch"><tr>

        <tr>

          <td colspan="2" bgcolor="#FFFFFF" class="text_searchbold" valign="top">

<!--

              <p><trans:showPageMessage label="login.search" />

                <select name="search">

                  <option value="all" selected><trans:showPageMessage label="login.alldatabase" /></option>

                  <option value="pro"><trans:showPageMessage label="login.projects" /></option>

                  <option value="org"><trans:showPageMessage label="login.organizations" /></option>

                  <option value="pers"><trans:showPageMessage label="login.involvedpersons" /></option>

                  <option value="aida">AIDA</option>

                </select>

                <br><br>

-->

                <trans:showPageMessage label="login.keywords" />&nbsp;

<input type="hidden" name="stype" value="simple">

                <input type="text" name="stext" size="12" maxlength="256">

                <input type="submit" name="Search" value="Search" class="butonsave">

                <br>
<div class="text"><trans:showPageMessage label="login.keywordsoption" /></div>
                <br>

                <img src=<%=ctx%>/images/arrow_blue.gif hspace=4>&nbsp;Try our <a href="<%=ctx%>/activity/search?mode=newsearch">Advanced

                Search</a></p>

            </td>

        </tr></form>

      </table>

</td>

    <td width="50%" valign="top">

      <table align="center" width="100%" border="0" cellpadding="5" cellspacing="1" background=images/pixelbgtable.gif>

        <form action="<%=ctx%>/usr.login" method="POST" name="theform">

         

        

        

          <tr bgcolor="#FFFFFF">

            <td colspan="2" class="textalb" background=images/pixelbgtable.gif><trans:showPageMessage label="login.logininfo" /></td>

          </tr>

          <% if (errors != null) { %>

          <tr bgcolor="#FFFFFF">

            <td colspan="2" class="text_searchBold">

              <% for ( int i = 0; i < errors.length; i++ ) { %>

              <trans:showPageMessage label='<%=errors[i]%>' /><br>

              <% } %>

            </td>

          </tr>

          <% } %>

       <% if (user == null) {%>

          <tr bgcolor="#FFFFFF">

            <td width="50%" align="right" class="text_searchBold"><trans:showPageMessage label="page.login" />:

            </td>

            <td>

              <input size="10" type="text" name="login" value="<%=last_logged_usr%>">

            </td>

          </tr>

          <tr bgcolor="#FFFFFF">

            <td width="50%" align="right" class="text_searchBold"><trans:showPageMessage label="form.pass" />:

            </td>

            <td>

              <input size="10" type="password" name="pass">

            </td>

          </tr>

          <tr bgcolor="#FFFFFF">

               <td colspan="2" align="center">

               <input name="blogin"

                    class="butonsave"

                    onclick="javascript:do_login();"

                    type=submit

                    value='<trans:showPageMessage label="login.blogin" hide_link="true"/>'/>

</td></tr>

               <% } %>



<% if (user!=null) { %>

          <tr bgcolor="#FFFFFF">

            <td colspan="2" align="center" class=text_searchbold>

<%if (ar.canDo(request,Perms.OBJECT_SUBMIT)){ %>            

              <div align="left"><img src=<%=ctx%>/images/arrow_blue.gif hspace=4><a href=<%=ctx%>/editActivity></a><a href=<%=ctx%>/editActivity><trans:showPageMessage label="login.create" /></a>

               <p>

<%}%>

<%if (ar.canDo(request,Perms.ADMIN_TOOLS)) { %>            
<p>
                <img src=<%=ctx%>/images/arrow_blue.gif hspace=4><a href=<%=ctx%>/admin.jsp></a><a href=<%=ctx%>/admin.jsp><trans:showPageMessage label="login.admin" /></a>


<%}%>
<p>

            <img src=<%=ctx%>/images/arrow_blue.gif hspace=4><a href="<%=ctx%>/desktop.do">My Desktop</a></p>

<p>

            <img src=<%=ctx%>/images/arrow_blue.gif hspace=4><a href="<%=ctx%>/usr/uedit?action=edit&id=<%=user.getId()%>">My Account</a></p>


</div>

            </td>

          </tr>

<% } %>

<% if (user==null) { %>

          <tr bgcolor="#FFFFFF">

            <td colspan="2" align="center" class=text_searchbold> New user? Click <a href="<%=ctx%>/usr/uedit">here</a>

            to register.

            	<br>

         	Forgot your password? Click <a href='<html:rewrite page="/pwdrec.do?mode=form"/>'>here</a>

            </td>

         

          </tr>

<%}%>

        </form>

      </table>

</td>


</tr>

</table>

<script language="javascript">

<% if (last_logged_usr.length() > 0 && user==null) { %>

     document.theform.pass.focus();

     document.theform.pass.selected=1;



<% } %>



         function do_login() {

               if (eval("document.theform.login.value") == "") {

                    alert("No username specified");

                    return false;

               }



               document.theform.blogin.disabled = 1;

               document.cookie = "<%=LoginServlet.LAST_LG_USR_COOKIE%>" + "=" +

                    escape(document.theform.login.value);

               document.theform.submit();

          }





</script>







